/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Carito
 */
@Entity
@Table(name = "MAC")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Mac.findAll", query = "SELECT m FROM Mac m"),
    @NamedQuery(name = "Mac.findByNoMac", query = "SELECT m FROM Mac m WHERE m.macPK.noMac = :noMac"),
    @NamedQuery(name = "Mac.findByRsa", query = "SELECT m FROM Mac m WHERE m.rsa = :rsa"),
    @NamedQuery(name = "Mac.findByIdusuario", query = "SELECT m FROM Mac m WHERE m.macPK.idusuario = :idusuario"),
    @NamedQuery(name = "Mac.findByIdempresa", query = "SELECT m FROM Mac m WHERE m.macPK.idempresa = :idempresa")})
public class Mac implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected MacPK macPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RSA")
    private BigInteger rsa;
    @JoinColumns({
        @JoinColumn(name = "IDUSUARIO", referencedColumnName = "IDUSUARIO", insertable = false, updatable = false),
        @JoinColumn(name = "IDEMPRESA", referencedColumnName = "IDEMPRESA", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Usuario usuario;

    public Mac() {
    }

    public Mac(MacPK macPK) {
        this.macPK = macPK;
    }

    public Mac(MacPK macPK, BigInteger rsa) {
        this.macPK = macPK;
        this.rsa = rsa;
    }

    public Mac(String noMac, BigInteger idusuario, BigInteger idempresa) {
        this.macPK = new MacPK(noMac, idusuario, idempresa);
    }

     @XmlElement
    public MacPK getMacPK() {
        return macPK;
    }

    public void setMacPK(MacPK macPK) {
        this.macPK = macPK;
    }

      @XmlElement
    public BigInteger getRsa() {
        return rsa;
    }

    public void setRsa(BigInteger rsa) {
        this.rsa = rsa;
    }

    @XmlElement
    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (macPK != null ? macPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Mac)) {
            return false;
        }
        Mac other = (Mac) object;
        if ((this.macPK == null && other.macPK != null) || (this.macPK != null && !this.macPK.equals(other.macPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Mac[ macPK=" + macPK + " ]";
    }
    
}
